﻿@{
    Layout = "_Layout";
}
<div id="app">
    <el-row>
        <el-col :span="24">
            <div class="grid-content bg-purple-dark">
                <el-input v-model="filterCourseName" placeholder="请输入规则名称" style="width:300px;" clearable></el-input>
                <el-select v-model="filterCourseType" placeholder="选择规则类型">
                    <el-option :key="-1" label="所有" :value="-1">
                    </el-option>
                    <el-option :key="0" label="现场课程" :value="0">
                    </el-option>
                    <el-option :key="1" label="线上课程" :value="1">
                    </el-option>
                </el-select>
                <el-button type="primary" v-on:click="loadTableData" style="margin-left:10px;width:98px;">搜索</el-button>
                <el-button type="primary" v-on:click="showAdd">添加课程</el-button>
            </div>
        </el-col>
    </el-row>
    <hr class="line-gray" />
    <el-row>
        <div class="table-container">
            <el-table :data="tableData" style="width:100%">
                <el-table-column type="index" width="50" label="编号">

                </el-table-column>
                <el-table-column label="名称" width="200" property="name">

                </el-table-column>
                <el-table-column label="类型" width="100" property="CourseType">
                    <template slot-scope="scope">
                        <span v-if="scope.row.courseType===0" style="color:#409EFF">现场课程</span>
                        <span v-else style="color:#67C23A">在线课程</span>
                    </template>
                </el-table-column>
                <el-table-column label="类型" width="100" property="CourseType">
                    <template slot-scope="scope">
                        <i class="el-icon-picture-outline" 
                           v-on:mouseover="showListImage(scope.row.listImage)"
                           v-on:mouseout="hideListImage"
                           v-popover:list-image-popover></i>
                    </template>
                </el-table-column>
                <el-table-column label="课时数" width="120" property="classCount">
                    
                </el-table-column>
                <el-table-column label="每节时长(Min)" width="120" >
                    <template slot-scope="scope">
                        <span>{{scope.row.duration}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="适合年龄段" width="100" property="forAge">
                    
                </el-table-column>
                <el-table-column label="简介" width="100" property="introdution">

                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" v-on:click="editCourse(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" v-on:click="deleteCourse(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </el-row>
    <!--列表图图片弹窗-->
    <el-popover ref="list-image-popover"
                placement="right"
                width="400"
                trigger="hover">
        <el-image style="width: 100%; height:400px;"
                  :src="imageUrl"
                  fit="contain">
        </el-image>
    </el-popover>
</div>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            userType: null,  // 用户类型
            insId: null,
            filterCourseName: '',
            filterCourseType: null,
            addDialogVisible: false,
            formLabelWidth: '100px',
            // 表格数据
            tableData: [],

            imageUrl:'',
        },
        methods: {
            // 显示添加对话框
            showAdd() {  // 显示添加对话框
                window.location.href = `/course/add?actionType=add`
            },

            // 编辑课程
            editCourse(index, row) {  // 修改
                window.location.href = `/course/add?actionType=edit&id=${row.id}`
            },

            // 显示列表图片
            showListImage(image) { 
                let vm = this;
                debugger;
                vm.imageUrl = image.url;

            },


            // 隐藏列表图片
            hideListImage() { 
            
            },


            // 表格中"活动"选中改变
            isActiveChange(row) {
                let vm = this;
                debugger;
                let value = null;
                if (row.isActive) {
                    value = 'true';
                }
                else {
                    value = 'false';
                }
                axios.get(`/api/Course/switch-isActive?id=${row.id}&value=${value}`)
                    .then((res) => {
                        if (res.data.code === 0) {
                            vm.$message({
                                message: res.data.msg,
                                type: 'success'
                            });
                        }
                        else {
                            vm.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }
                    });
            },

            // 删除课程
            deleteCourse(index, row) {
                var that = this;
                that.$confirm('角色将被删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/api/Course/delete-Course?Id=${row.id}`)
                        .then((res) => {
                            if (res.data.code === 0) {
                                that.$message({
                                    message: res.data.msg,
                                    type: 'success'
                                });
                                that.addDialogVisible = false;
                                that.loadTableData();
                            }
                            else {
                                that.$message({
                                    message: res.data.msg,
                                    type: 'error'
                                });
                            }
                        });
                });
            },

            // 加载表格数据
            loadTableData() {
                let vm = this;
                debugger;
                axios.get(`/api/course/get-Course-list?name=${vm.filterCourseName}&type=${vm.filterCourseType}`)
                    .then((res) => {
                        vm.takePartCourses = res.data.data;
                    });
            }
        },
        created() {
            let vm = this;
            vm.userType = @ViewBag.UserType;
            if (vm.userType === 1) {
                vm.insId = @ViewBag.InsId
                }
            vm.loadTableData();
        },
        mounted() {

        }
    });


</script>
<style>

</style>